package man

import (
	"dub/app/web/managent/controller"
	"dub/app/web/managent/mandefine"
	"dub/define"
	"dub/define/grpcmodel"
	"fmt"
)

type AgentManBaseController struct {
	controller.AgentBaseController
}

//权限过滤
func (a *AgentManBaseController) Prepare() {
	a.AgentBaseController.DubBaseController.Prepare()

	ses_val := a.GetSession(define.Web_Session_Name_Man_Login_Use)
	if ses_val == nil && mandefine.Lobby_Login_Url != "" {
		a.Ctx.Redirect(302, mandefine.Lobby_Login_Url)
		return
	}
	if login_info, login_ok := ses_val.(grpcmodel.ModelSecRpcUseResLogin); !login_ok {
		a.Ctx.Redirect(302, mandefine.Lobby_Login_Url)
		return
	} else {
		url := fmt.Sprintf("%s%s", mandefine.Proxy_Url, a.Ctx.Request.URL.Path)
		has_do := false
		//判断是否有权限执行操作PhyAuths
		for _, auth := range login_info.PhyAuths {
			if auth == url {
				has_do = true
				break
			}
		}
		if !has_do {
			a.Ctx.Redirect(302, mandefine.Lobby_Login_Url)
			return
		}

		//把所有实体权限放到前台用于判断是否肯有按钮级的权限
		a.Data["PhyAuths"] = login_info.GetPhyAuths()
	}
}
